package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.ClientCase;
import cn.wolfcode.crm.mapper.ClientCaseMapper;
import cn.wolfcode.crm.query.impl.ClientCaseQuery;
import cn.wolfcode.crm.service.IClientCaseService;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class ClientCaseServiceImpl implements IClientCaseService {
    @Autowired
    ClientCaseMapper clientCaseMapper;

    public void delete(Long id) {
        clientCaseMapper.deleteByPrimaryKey(id);
    }

    public void saveOrUpdate(ClientCase record) {
        if (record.getId() != null) {
            clientCaseMapper.updateByPrimaryKey(record);
        } else {
            clientCaseMapper.insert(record);
        }
    }

    public ClientCase get(Long id) {
        return clientCaseMapper.selectByPrimaryKey(id);
    }

    public List<ClientCase> getAll() {
        return clientCaseMapper.selectAll();
    }


    public PageResult query(ClientCaseQuery qo) {
        int rows = clientCaseMapper.queryForCount(qo);
        if (rows == 0) {
            new PageResult(rows, Collections.EMPTY_LIST);
        }
        List<ClientCase> result = clientCaseMapper.queryForList(qo);
        return new PageResult(rows, result);
    }

    @Override
    public void insert(ClientCase car) {
        clientCaseMapper.insert(car);
    }
}
